package com.flycms.web.escontroller;

import com.flycms.core.entity.RestDataVo;
import com.flycms.esmodule.model.EsBase;
import com.flycms.esmodule.service.EsBaseService;
import com.flycms.esmodule.service.EsCaseService;
import com.flycms.esmodule.service.EsSoftService;
import com.flycms.esmodule.service.EsSolutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangzt
 * @version 1.0
 * @date 2020/3/14 22:05
 */
@RestController
public class EsController {

    @Autowired
    public EsSoftService esSoftService;
    @Autowired
    public EsSolutionService esSolutionService;
    @Autowired
    public EsCaseService esCaseService;
    @Autowired
    public EsBaseService esBaseService;


    @GetMapping(value = "/es/base/search")
    public RestDataVo getBaseSearch(@RequestParam(value = "keywords") String keywords,
                                @RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,
                                @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize){
        Page<EsBase> esBaseByKeys = esBaseService.getEsBaseByKeys(keywords, PageRequest.of(pageIndex-1, pageSize));
        if(esBaseByKeys!=null&&esBaseByKeys.getContent().size()!=0){
            return RestDataVo.PAGE(esBaseByKeys.getContent(),pageIndex,pageSize,(int)esBaseByKeys.getTotalElements());
        }
        return RestDataVo.ERROR("没有发现您要搜索的数据");
    }



}
